Skip to content

fix(analyzer): order NAT Gateway deletion before IGW / VPCGatewayAttachment on destroy - #823

Merged
go-to-k merged 3 commits into
mainfrom
fix/817-igw-nat-delete-dep
Jun 13, 2026
Merged

fix(analyzer): order NAT Gateway deletion before IGW / VPCGatewayAttachment on destroy#823
go-to-k merged 3 commits into
mainfrom
fix/817-igw-nat-delete-dep

Conversation

@go-to-k

@go-to-k go-to-k commented Jun 13, 2026

Copy link
Copy Markdown
Owner

Summary

Destroying a VPC + NAT Gateway + IGW stack attempted the VPCGatewayAttachment detach while the NAT Gateway's Elastic IP was still mapped → Network vpc-xxx has some mapped public address(es), after which the IGW delete hung (~19 min observed). This is an implicit delete-dependency gap: IGW detach/delete must wait for NAT Gateway deletion (which releases/decouples the EIP) first.

Fix

Added to IMPLICIT_DELETE_DEPENDENCIES in src/analyzer/implicit-delete-deps.ts:

  • AWS::EC2::InternetGatewayAWS::EC2::NatGateway (alongside the existing VPCGatewayAttachment)
  • AWS::EC2::VPCGatewayAttachmentAWS::EC2::NatGateway (new key)

The map KEY is deleted after the listed types: the consumer injects DependsOn: [<key>] on each NatGateway, and the reversed destroy traversal deletes NAT first — matching CloudFormation's NAT-before-IGW ordering. These edges are consumed only in delete-scoped structures (addImplicitDeleteDependencies / the reverse-DAG destroy traversal), so create ordering is unaffected. EIP needs no rule — NAT references its EIP via Fn::GetAtt[EIP, AllocationId], so the existing reference-based reversed-delete already deletes NAT before EIP release.

Test plan

  • Unit (tests/unit/analyzer/implicit-delete-deps.test.ts): the IGW/VPCGatewayAttachment→NatGateway edges are produced; NatGateway/EIP are never KEYs (no outbound implicit edge); the no-self-cycle guard covers the new keys.
  • Real-AWS (vpc-nat-gateway: VPC + 4 subnets + IGW + VPCGatewayAttachment + NAT + EIP + routes): deploy + destroy clean — 21 deleted, 0 errors, 0 orphans, with NAT deleted before the IGW/EIP. Pre-fix this destroy failed on the mapped-address error + IGW hang.

Independent review

Code review clean — verified edge direction, no create-ordering side-effect (delete-only consumption), the EIP reference-ordering claim, and no cycle introduced.

Closes #817

go-to-k added 2 commits June 13, 2026 15:11
Destroying a VPC + NAT Gateway + IGW stack attempted the
VPCGatewayAttachment detach while the NAT Gateway's Elastic IP was still
mapped to the VPC's public address space, failing with "Network vpc-xxx
has some mapped public address(es)", after which the IGW delete hung
(~19 min observed). This was the first-run failure split out of the #804
incident as a separate issue.

Add two type-based implicit delete-dependency edges in
IMPLICIT_DELETE_DEPENDENCIES so the shared deploy DELETE phase and the
standalone destroy command order the teardown like CloudFormation does:

- AWS::EC2::InternetGateway now lists AWS::EC2::NatGateway (alongside its
  existing AWS::EC2::VPCGatewayAttachment dependee)
- AWS::EC2::VPCGatewayAttachment (new key) lists AWS::EC2::NatGateway

Both are deleted AFTER the NAT Gateway is gone, since NAT deletion
releases/decouples the EIP. No type-based rule is needed for the EIP
itself: the NAT Ref's its EIP via AllocationId, so the reversed delete
traversal already deletes the NAT before the EIP is released. The
injection logic naturally produces no edge when no NatGateway is in
state.

Tests: 4 unit assertions in implicit-delete-deps.test.ts (IGW-after-NAT
edge, VPCGatewayAttachment-after-NAT edge, no NatGateway/EIP key
registered; the existing no-self-cycle guard covers the new entries).
The existing vpc-nat-gateway integ fixture (VPC + public/private subnets
+ IGW + NatGateway + EIP) exercises this teardown end-to-end.

Closes #817
@go-to-k
go-to-k force-pushed the fix/817-igw-nat-delete-dep branch from 91a87ce to 2eda56d Compare June 13, 2026 06:12
@go-to-k
go-to-k merged commit cbeb742 into main Jun 13, 2026
5 checks passed
@go-to-k
go-to-k deleted the fix/817-igw-nat-delete-dep branch June 13, 2026 06:17
github-actions Bot pushed a commit that referenced this pull request Jun 13, 2026
## [0.220.3](v0.220.2...v0.220.3) (2026-06-13)

### Bug Fixes

* **analyzer:** order NAT Gateway deletion before IGW / VPCGatewayAttachment on destroy ([#823](#823)) ([cbeb742](cbeb742))
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 0.220.3 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

destroy: IGW/VPCGatewayAttachment delete must wait for NAT Gateway deletion + EIP release (implicit delete-dep gap)

1 participant